package com.itheima.pattern.singleton.demo4;

//双重检查锁模式.在多线程的情况下可能出现空指针问题
public class Singleton {
    private Singleton(){}

    //volatile解决空指针问题
    private static volatile Singleton instance;

    //双重检查锁方式，解决了单例，性能，线程安全问题
    public static Singleton getInstance(){
        if(instance==null){
            synchronized (Singleton.class){
                if(instance==null){
                    instance=new Singleton();
                }
            }
        }
        return instance;
    }
}
